//index.js
//获取应用实例
import Toast from "../../miniprogram_npm/vant-weapp/toast/toast";
import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog';
const amapFile = require('../../common/javascript/amap-wx.js')
const app = getApp()
//获取 log 日志打印
const log = new app.appLogs()
//获取 http 网络请求
const http = new app.appHttp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    theme: {},
    tabbar: {},
    //天气数据
    weather: {},
    weatherImage: '/common/image/weather_yin.png'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    const _this = this
    wx.setStorage({
      key: 'user',
      data: app.globalData.userInfo
    })
    app.editTabbar()
    this.setData({
      theme: app.globalData.theme,
    })
    wx.setNavigationBarTitle({
      title: app.globalData.appTitle
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: app.globalData.theme.themeColor[0]
    })
    //获取高德
    let aMap = new amapFile.AMapWX({
      key: app.globalData.aMapKey
    })
    aMap.getWeather({
      success: res => {
        log.l('天气数据 获取成功: ' + JSON.stringify(res))
        _this.setData({
          weather: res
        })
        switch (res.weather.data) {
          default:
            _this.data.weatherImage = '/common/image/weather_yin.png'
            break
          case "晴":
            _this.data.weatherImage = '/common/image/weather_qing.png'
            break
          case "多云":
            _this.data.weatherImage = '/common/image/weather_duoyun.png'
            break
          case "雷阵雨":
            _this.data.weatherImage = '/common/image/weather_lzy.png'
            break
          case "小雨":
            _this.data.weatherImage = '/common/image/weather_yu.png'
            break
          case "大雨":
            _this.data.weatherImage = '/common/image/weather_yu.png'
            break
          case "中雨":
            _this.data.weatherImage = '/common/image/weather_yu.png'
            break
          case "阵雨":
            _this.data.weatherImage = '/common/image/weather_yu.png'
            break
          case "暴雨":
            _this.data.weatherImage = '/common/image/weather_yu.png'
            break
        }
        _this.setData({
          weatherImage: _this.data.weatherImage
        })
      },
      fail: res => {
        log.l('天气数据 获取失败: ' + JSON.stringify(res))
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onItemInfo1: function (e) {
    wx.navigateTo({
      url: '../index/collection/collection',
    })
  }
})